'************************************************************************************
' Copyright © 2003-2005 Kathleen Dollard
'
' This software is provided 'as-is', without any express or implied warranty. In no 
' event will the author be held liable for any damages arising from the use of this
' software.
' 
' You may use this software for any purpose, including commercial applications, 
' and you may redistribute this software as part of application delivery: however, 
' this copyright notice may not be removed and you may not otherwise redistribute 
' this software directly other than providing a link to wwww.gendotnet.com. 
'
' You may alter this software to better server your needs (I'd like to hear about your 
' changes in order to make the software better). If you alter the softwre, you must  
' clearly mark it as altered and must not be misrepresented as the original software.
' nor wholly your original work.
'*************************************************************************************
Option Strict On
Option Explicit On 

' Summary: This class contains utility method that can be overridden 
'          in the UserUtilityOverride class. This class should NOT be
'          changed by the user.
Imports System

Namespace KADGen.Utility
   Public Class BaseUtilityOverrides
      Public Overridable Function GetSingular(ByVal name As String) As String
         Dim testName As String
         If name Is Nothing Then
            Return ""
         Else
            testName = name.Trim
            If testName.ToLower.EndsWith("analyses") Then
               Return testName.Substring(0, testName.Length - 2) & "is"
            Else
               If testName.ToLower.EndsWith("children") Then
                  Return testName.Substring(0, testName.Length - 8) & "Child"
                  'ElseIf testName.ToLower.EndsWith("criteria") Then
                  '   Return testName.Substring(0, testName.Length - 1) & "on"
               ElseIf testName.ToLower.EndsWith("clauses") Then
                  Return testName.Substring(0, testName.Length - 1)
               ElseIf testName.ToLower.EndsWith("ss") Or Not testName.ToLower.EndsWith("s") Then
                  ' This is generally not a plural    
                  Return testName
               ElseIf testName.ToLower.EndsWith("us") Then
                  ' This is generally not a plural
                  Return testName
               ElseIf testName.ToLower.EndsWith("sses") Then
                  Return testName.Substring(0, testName.Length - 2)
               ElseIf testName.ToLower.EndsWith("uses") Then
                  Return testName.Substring(0, testName.Length - 2)
               ElseIf testName.ToLower.EndsWith("ies") Then
                  ' NOTE: You can't tell from here if it used to be ey or y. You must
                  '       add the specific cases important to you.
                  Return testName.Substring(0, testName.Length - 3) & "y"
               ElseIf testName.ToLower.EndsWith("s") Then
                  Return testName.Substring(0, testName.Length - 1)
               Else
                  Return testName ' We shouldn't be able to get here
               End If
            End If
         End If
      End Function

      Public Overridable Function GetPlural(ByVal name As String) As String
         ' Simple rules, you may need to expand these. Create new Case entries 
         ' above the Else for any exceptions important to you
         Dim testName As String
         If name Is Nothing Then
            Return ""
         Else
            testName = GetSingular(name)
            If testName.ToLower.EndsWith("analysis") Then
               Return testName.Substring(0, testName.Length - 2) + "es"
            Else
               If testName.ToLower.EndsWith("child") Then
                  Return testName.Substring(0, testName.Length - 5) & "Children"
                  'ElseIf testName.ToLower.EndsWith("criterion") Then
                  '   Return testName.Substring(0, testName.Length - 2) & "a"
               ElseIf testName.ToLower.EndsWith("key") Then
                  Return testName & "s"
               ElseIf testName.EndsWith("ey") Then
                  Return testName.Substring(0, testName.Length - 2) & "ies"
               ElseIf testName.EndsWith("ay") Then
                  Return testName.Substring(0, testName.Length) & "s"
               ElseIf testName.EndsWith("y") Then
                  Return testName.Substring(0, testName.Length - 1) & "ies"
               ElseIf testName.EndsWith("ss") Then
                  Return testName.Substring(0, testName.Length) & "es"
               ElseIf testName.EndsWith("us") Then
                  Return testName.Substring(0, testName.Length) & "es"
               ElseIf testName.EndsWith("s") Then
                  Return testName.Substring(0, testName.Length - 1) & "es"
               Else
                  Return testName & "s"
               End If
            End If
         End If
      End Function
   End Class
End Namespace